package main

import (
	"log"
	"os"
	"server_cluster/common/gdconf"
	"server_cluster/common/logger"
	"server_cluster/logic/db"
	"server_cluster/logic/game_config"
	"server_cluster/logic/gamelogic"
	"server_cluster/logic/sharemem"
	"strconv"
)

func main() {
	game_config.InitConfig()

	err := db.InitDB()
	if err != nil {
		panic("init db fail.")
	}
	game_config.GetConfig().RebuildSelf(db.Conn)

	logger.InitLogger("meminit", game_config.GetConfig().LogLevel)
	defer logger.CloseLogger()

	shmid := sharemem.GetShm()
	if shmid <= 0 {
		log.Fatal("get myshm fail.")
		return
	}
	err = os.WriteFile("./shmid", []byte(strconv.Itoa(int(shmid))), 0644)
	if err != nil {
		panic(err)
	}
	var myshm = sharemem.MyShm
	//
	if myshm.Status == 1 || myshm.StatusSync == 1 {
		panic("server is running.")
	}

	sharemem.InitShm()

	gdconf.LoadGameDataConfig(db.Conn)
	gamelogic.LoadConfigData2Shm()
	logger.Info("share-mem-init ok.")
}
